<?php
	defined( "AZ_EXE_" ) or die ( "CORE VARIABLE IS NOT DEFINED." );
	class UserController extends Controller {
		public function index(){
			$page = $this->loadController("Page");
            $user = SESSION::get("user") ;
            if ( $user!=null && $user->id != "" && $user->email != "" && $user->password != "" ){
                $userOption = Basic::getVar("user_option")==false||Basic::getVar("user_option")==""?3:Basic::getVar("user_option");
                $start = Basic::getVar("start");
                $perpage = Basic::getVar("perpage");
                $search = Basic::getVar("search");
                $start = is_numeric($start)&&$start<1?1:$start;
                $perpage = is_numeric($perpage)&&$perpage>0?$perpage:20;
                $searchColumns = Basic::getVar("search_column")?Basic::getVar("search_column"):false;
                $sortColumn = Basic::getVar("sort_column")?Basic::getVar("sort_column"):"first_name";
                $sortCriteria = Basic::getVar("sort_criteria")?Basic::getVar("sort_criteria"):false;
                $user = $this->loadModel("User");
                $userRecords = ($userOption==3?$user->display($start,$perpage,$search,$searchColumns,$sortColumn,$sortCriteria):($userOption==1?($user->displayRequest($start,$perpage,$search,$searchColumns,$sortColumn,$sortCriteria)):$user->displayPremium($start,$perpage,$search,$searchColumns,$sortColumn,$sortCriteria))) ;
                $this->set("user_option",$userOption );
                $this->set("currentPage",$start);
                $this->set("perpage",$perpage);
                $this->set("search",$search);
                $this->set("searchColumns",$searchColumns);
                $this->set("sortColumn",$sortColumn);
                $this->set("sortCriteria",$sortCriteria);
                $this->set("search",$search);
                $this->set("users",$userRecords);
                $this->set( "title" , "SMECA - User List" );
                $this->setLanguage( "English" );
                $this->set("selectedMenu","USR");
                
                //print_r( $userRecords );
                //exit();
                
                $this->renderDefault("user_display","user");
            }else{
                $this->redirect(array("com"=>"page","action"=>"login"));
            }
		}
		public function resetpasswd(){
			$this->renderDefault("resetpasswd","user");
		}
		
		public function setnewpasswd(){
			$user_id = Basic::getVar("user_id");
			$token = Basic::getVar("token");
			$user = $this->loadModel("User");
			$user_info = $user->find($user_id);
			$user_info = $user_info[0];
			$this->set("valid",false);
			if($user_info->reset==$token){
				$this->set("user_id",$user_info->id );
				$this->set("valid",true);
			}
			$this->renderDefault("newpasswd","user");
		}
		
		public function setnewpasswdpro(){
			$user_id = Basic::getVar("user_id");
			$password = Basic::getVar("password");
			if($user_id!==false&&$password!==false){
				$user = $this->loadModel("User");
				$password=md5($password);
				$user->editPassword($user_id,$password);
				$user_info = $user->find($user_id);
				$user_info = $user_info[0];
				SESSION::set("user",$user_info);
				echo 1 ;
			}else{
				echo 0;
			}
		}
		
		public function resetpro(){
			$email = Basic::getVar("email");
			$user = $this->loadModel("User");
			$user_info = $user->checkmail($email);
			$user_info = $user_info[0];
			if(isset($user_info)&&$user_info!==NULL){
				$stringReset = md5(date("YmdHis"));
				$ref = $user->setStringReset($user_info->id,$stringReset);
				/* SENDING MAIL TO CLIENT */
				$message ='
							<html>
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							</head>
							<body>';
				$message .= '
								<div style="margin-bottom:15px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:11px;">
									<div align="center"> <img src="' . BASE_URL . IMG_FOLDER. 'logo.png" /> </div>
								</div>
								<p  style="width:680px;margin:0 auto 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
									Date &amp; Time : ' . Date('D, Y-m-d h:i:s A') . '
								</p>
								<p  style="width:680px;margin:0 auto 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
									Reference Number : ' . $ref . '
								</p>
								<table style="FONT-FAMILY:Cambria,Arial;BORDER-COLLAPSE:collapse" cellspacing="0" cellpadding="5" width="680" align="center" border="0">
									<tbody>
									<tr>
									</tr>
									<tr valign="top">
										<td style="FONT-SIZE:11px" colspan="2" >
											<p>
											Dear Member,<br><br>
											
											Please click on the link below in order to reset a new password.<br><br>
											<a href="'. BASE_URL . '?com=user&action=setnewpasswd&user_id='.$user_info->id.'&token='.$stringReset.'" >
													'. BASE_URL . '?com=user&action=setnewpasswd&user_id='.$user_info->id.'&token='.$stringReset.'
											</a><br><br>
					   
											Sincerely Yours,<br><br><br>
					   
					   
											General Administration<br>
											Smeca Clinic<br>
											Tel: (61) 414 282 552 / 403 699 334<br>
											Email: admin@smecaclinic.com<br>
											Page: <a href="http://www.smecaclinic.com">http://www.smecaclinic.com</a>
				
											</p>
									   	</td>
									</tr>
									</tbody>
								</table>
							';
				
				$message .='</body></html>';
				//die($message);
				
				//---------------------------------------------------------
				// To send HTML mail, the Content-type header must be set |
				//---------------------------------------------------------
				$header  = 'MIME-Version: 1.0' . "\r\n";
				$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
				//---------------------
				// Additional headers |
				//---------------------
				$subject = "Request for Password Reset";
				$to = $user_info->email ;
				$name = "SMECA CLINIC";
				$header .= 'From:' . $name . " <admin@smecaclinic.com>\r\n";
				//Just add a Simple hack here to show the SMTP conversation
				if(mail($to, $subject, $message, $header)){
					echo 1;
				}else{
					echo 0;
				}
				/* SENDING MAIL TO CLIENT */
			}else{
				echo 0;
			}
		}
		
		public function display(){
			
		}
		
		public function getTotalRows(){
			
		}
		
		public function add(){
			$expire = $this->loadModel("UserExpire");
			$expire_infos = $expire->getExpires();
			$expire_datas = array(); 
			foreach( $expire_infos As $key => $expire_info ){
				$expire_datas[$expire_info->id] = $expire_info->label . " : " . $expire_info->price . " $";
			}
			$this->set('expires',$expire_datas);
			
			$this->set("selectedMenu","USR");
			$this->set( "title" , "SMECA - User New" );
			$this->setLanguage( "English" );
			$this->renderDefault("new_user", "user" );
		}
		public function addProcess(){
			$firstName = Basic::getVar("first_name");
			$lastName = Basic::getVar("last_name");
			$email = Basic::getVar("email");
			$gender = Basic::getVar("gender");
			$phone = Basic::getVar("phone");
			$type = Basic::getVar("type");
			$address = Basic::getVar("address");
			$password = Basic::getVar("password");
			$user = $this->loadModel("User");
			$this->set( "request" , $_REQUEST );
			if( $firstName && $lastName && $email && $gender!==false && $password && $type!== false ){
				if ( count( $user->checkmail($email) ) > 0 ){
					$result = 1 ;
				}else{
					$this->set("info","User is added successfully.");
					$password = md5($password);
					$user->add( $firstName , $lastName , $email , $gender , $phone , $address , $password , $type );
					$userinfo = $user->checkmail($email);
					if($type==2){
						$datas["userexpireds"]["user_id"] = $userinfo[0]->id;
						$datas["userexpireds"]["expire_id"] = Basic::getVar("expire_id");
						$datas["userexpireds"]["start_date"] = Basic::getVar("start_date");
						$datas["userexpireds"]["end_date"] = Basic::getVar("end_date");
						$datas["userexpireds"]["status"] = 1 ;
						$datas["userexpireds"]["modified_by"] = $_SESSION["user"]->id;
						$expire = $this->loadModel("Expire");
						$expire->add($datas);
					}
				}
			}
			else{
				$this->set("info","Failed to add user.");
			}
			$this->redirect(array("com"=>"user","action"=>"index"));
		}
		
		public function delete(){
			$id = Basic::getVar("id");
			$user = $this->loadModel("User");
			if ( $id ){
				$this->set("info","User(s) delete successfully.");
				$user->delete( $id );
			}else{
				$this->set("info","Failed to delete user(s) successfully.");
			}
			$this->redirect(array("com"=>"user","action"=>"index"));
		}
		public function deleteactivity(){
			$id = Basic::getVar("id");
			$user = $this->loadModel("User");
			if ( $id ){
				$this->set("info","User Activity delete successfully.");
				$user->deleteActivity( $id );
			}else{
				$this->set("info","Failed to delete user activity successfully.");
			}
			$this->redirect(array("com"=>"user","action"=>"useractivity"));
		}
		public function edit(){
			$id = Basic::getVar("id");
            $user = $this->loadModel("User");
            $expire = $this->loadModel("UserExpire");
            if ( $id ){
                $this->set("selectedMenu","USR");
                $this->set( "title" , "SMECA - User Edit" );
                $this->setLanguage( "English" );
                $userinfo = $user->find( $id );
                //print_r( $userinfo );
                $expireinfo = $expire->getExpireWithUserId($userinfo[0]->id);
                //print_r( $expireinfo );
                $this->set("expireinfo",$expireinfo[0]);
                $this->set("user",$userinfo[0]);
                
                $expire_infos = $expire->getExpires();
                $expire_datas = array();
                foreach( $expire_infos As $key => $expire_info ){
                    $expire_datas[$expire_info->id] = $expire_info->label . " : " . $expire_info->price . " $";
                }
                $this->set('expires',$expire_datas);
                
                $this->renderDefault("edit_user", "user" );
            }
            else{
                $this->redirect(array("com"=>"user","action"=>"index"));
            }
		}
		
		public function account(){
			$user = $this->loadModel("User");
            $expire = $this->loadModel("Expire");
            $userexpire = $this->loadModel("UserExpire");
            if ( isset( $_SESSION["user"] ) && $_SESSION["user"] !== null ){
                $userinfo = $user->find($_SESSION["user"]->id) ;
                $expires = $expire->display();
                $expire_info = $userexpire->getExpireWithUserId($_SESSION["user"]->id);
                $userinfo = is_array($userinfo)&&count($userinfo)>0?$userinfo[0]:null;
                $expire_info = is_array($expire_info)&&count($expire_info)>0?$expire_info[0]:null;
                $this->set("user",$userinfo);
                $this->set("expires",$expires);
                $this->set("expire_info",$expire_info);
            }
            $this->renderDefault("profile","user");
		}
		
		public function register(){
			$this->renderDefault("register","user");
		}
		
		public function registerpro(){
			$firstName = Basic::getVar("first_name");
			$lastName = Basic::getVar("last_name");
			$email = Basic::getVar("email");
			$gender = Basic::getVar("gender");
			$phone = Basic::getVar("phone");
			$password = Basic::getVar("password");
			$address = Basic::getVar("address")!==false?Basic::getVar("address"):"";
			$captcha = Basic::getVar("security_code")!==false?Basic::getVar("security_code"):"";
			$result = 0 ;
			if( $firstName && $lastName && $email && $gender!== false && $phone  && $password && ($_SESSION["security_code"]==$captcha) ){
				$user = $this->loadModel("User");
				if ( count( $user->checkmail($email) ) > 0 ){
					$result = 1 ;
				}else{
					$password = md5($password);
					$user->add( $firstName , $lastName , $email , $gender , $phone , $address , $password , 3 );
					$userinfo = $user->validate($email,$password);
					if ( $userinfo != null ){
						SESSION::set("user",$userinfo[0]);
						$result = 2;
					}
				}
			}
			echo $result ;
		}
		
		public function editprocess(){
			$id = Basic::getVar("id");
			$firstName = Basic::getVar("first_name");
			$lastName = Basic::getVar("last_name");
			$email = Basic::getVar("email");
			$gender = Basic::getVar("gender");
			$phone = Basic::getVar("phone");
			$address = Basic::getVar("address");
			$type = Basic::getVar("type");
			$user = $this->loadModel("User");
			if( $id && $firstName && $lastName && $email && $gender !== false && $type ){
				$this->set("info","User information is updated succeffully.");
				$user->edit( $id , $firstName , $lastName , $email , $gender , $phone , $address , $type );
				$expire = $this->loadModel("UserExpire");
				if($type==2){
						$datas["userexpireds"]["expire_id"] = Basic::getVar("expire_id");
						$datas["userexpireds"]["start_date"] = Basic::getVar("start_date");
						$datas["userexpireds"]["end_date"] = Basic::getVar("end_date");
						$datas["userexpireds"]["status"] = 1 ;
						$datas["userexpireds"]["user_id"] = Basic::getVar("id");
						$datas["userexpireds"]["modified_by"] = $_SESSION["user"]->id;
						if(Basic::getVar("id_expire")===false||Basic::getVar("id_expire")===""){
							$expire->add($datas);
						}else{
							$datas["userexpireds"]["id"] = Basic::getVar("id_expire");
							$expire->edit($datas);
						}
				}
				else if($type==3){
					$expire->deleteWithUser($id);
				}
				if($type==2){
				/* SENDING MAIL TO CLIENT */
						$ref = $user->getRef("Approval of Premium Membership","APM",0); // APM = Approval of Premium Membership
						$message ='
							<html>
							<head>
							<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
							</head>
							<body>';
						$message .= '
								<div style="margin-bottom:15px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:11px;">
									<div align="center"> <img src="' . BASE_URL . IMG_FOLDER. 'logo.png" /> </div>
								</div>
								<p  style="width:680px;margin:0 auto 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
									Date &amp; Time : ' . Date('D, Y-m-d h:i:s A') . '
								</p>
								<p  style="width:680px;margin:0 auto 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
									Reference Number : ' . $ref . '
								</p>
								<table style="FONT-FAMILY:Cambria,Arial;BORDER-COLLAPSE:collapse" cellspacing="0" cellpadding="5" width="680" align="center" border="0">
									<tbody>
									<tr>
									</tr>
									<tr valign="top">
										<td style="FONT-SIZE:11px" colspan="2" >
											<p>
											Dear Member,<br><br>
									
											Please be informed that your request for a Premium Membership has now been approved.<br><br>
									
											Being a Premium Member, you are privileged to access a great number of resources and special services from Smeca Clinic.<br><br>
									
											For details, please refer to Terms and Conditions of Membership.<br><br>
									
											Sincerely Yours,<br><br><br>
									
									
											General Administration<br>
											Smeca Clinic<br>
											Tel: (61) 414 282 552 / 403 699 334<br>
											Email: admin@smecaclinic.com<br>
											Page: <a href="http://www.smecaclinic.com">http://www.smecaclinic.com</a>

											</p>
										</td>
									</tr>
									</tbody>
								</table>								
							';
						
						$message .='</body></html>';
						//die($message);
						//---------------------------------------------------------
						// To send HTML mail, the Content-type header must be set |
						//---------------------------------------------------------
						$header  = 'MIME-Version: 1.0' . "\r\n";
						$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
						//---------------------
						// Additional headers |
						//---------------------
						$subject = "Approval of Premium Membership";
						$to = $email ;
						$name = "SMECA CLINIC";
						$header .= 'From:' . $name . " <admin@smecaclinic.com>\r\n";
						//Just add a Simple hack here to show the SMTP conversation
						mail($to, $subject, $message, $header);			
				}			
				echo " 1";
			}
			else{
				$this->set("info","Failed to update user information.");
				echo " 2";
			}
			$this->redirect(array("com"=>"user","action"=>"index"));
		}
		
		public function validate(){
			$username = Basic::getVar("username");
			$password = Basic::getVar("password");
			$this->set( "datas" , $_REQUEST );
			$user = $this->loadModel("User");
			$password = md5($password);
			$userinfo = $user->validate($username,$password);
			//die(print_r($userinfo));
			if ( $userinfo != null ){//Basic::pr(SESSION::get('php_uri'));die();
				SESSION::set("user",$userinfo[0]);
				if(SESSION::get('php_uri') != ""){
					$url = SESSION::get('php_uri');
					SESSION::kill('php_uri');
					//$this->redirect(SESSION::get('tmp_url'));
				}else{
					echo "({'result':1})" ;
					//$this->redirect(array("com"=>"page","action"=>"index"));
				}
			}
			else{
				echo "({'result':0})" ;
				//$this->redirect(array("com"=>"page","action"=>"login"));
			}
		}
		
		public function editpassfront(){
			$result = 0 ;
			$id = Basic::getVar("id");
			$currentPass=Basic::getVar("current_password");
			$newPass=Basic::getVar("new_password");
			$user = $this->loadModel("User");
			if ( $id && $currentPass && $newPass ){
				$currentPass = md5($currentPass);
				$userInfo = $user->find($id);
				if ( !empty($userInfo) ){
					$userInfo = $userInfo[0];
					if ( $userInfo->password == $currentPass ){
						$newPass = md5($newPass);
						$userinfo = $user->editPassword( $id , $newPass );
						$result= 1 ;
					}
				}
			}
			echo $result;
		}
		
		public function editpasspro(){
			$id = Basic::getVar("id");
			$pass = Basic::getVar("pass");
			$user = $this->loadModel("User");
			if ( $id && $pass ){
				$pass = md5($pass);
				$userinfo = $user->editPassword( $id , $pass );
				$this->edit();
			}
			else{
				$this->redirect(array("com"=>"user","action"=>"index"));
			}
		}

		public function editpass(){
			$id = Basic::getVar("id");
			$user = $this->loadModel("User");
			if ( $id ){
				$this->set("selectedMenu","USR");
				$this->set( "title" , "SMECA - User Change Password" );
				$userinfo = $user->find( $id );
				$this->set("user",$userinfo[0]);
				$this->renderDefault("edit_pass_user", "user" );
			}
			else{
				$this->redirect(array("com"=>"user","action"=>"index"));
			}
		}
		
		public function accounteditpro(){
			$id = Basic::getVar("id");
			$firstName = Basic::getVar("first_name");
			$lastName = Basic::getVar("last_name");
			$gender = Basic::getVar("gender");
			$phone = Basic::getVar("phone");
			$user = $this->loadModel("User");
			if( $id && $firstName && $lastName && $gender !== false && $phone ){
				$user->accountedit( $id , $firstName , $lastName , $gender , $phone );
				$_SESSION["user"]->first_name = $firstName ;
				$_SESSION["user"]->last_name = $lastName ;
				$_SESSION["user"]->gender = $gender ;
				$_SESSION["user"]->phone = $phone ;
				echo 1 ;
			}else{
				echo 0 ;
			}
			
		}
		
		public function requestpremium(){
			$id = Basic::getVar("id");
            $type = Basic::getVar("type");
            $user = $this->loadModel("User");
            $userexpire = $this->loadModel("UserExpire");
            if ( $id && $type ){
                
                /*
                 0 => admin
                 1 => User request to be Premium
                 2 => Premium
                 3 => Free 
                 */
                list($expire_id,$expire_option)=explode(",",$type);
                $start = date_format(date_create("now"), "Y-m-d");
                $stop = explode("-",$start);
                $stop[1]=$stop[1]+$expire_option;
                if($stop[1]>12){
                    $stop[0]=$stop[0]+1;
                    $stop[1]=$stop[1]-12;
                }
                $stop = implode("-",$stop) ;
                
                $data = array("userexpireds"=>array("user_id"=>$id,"expire_id"=>$expire_id,"start_date"=>$start,"end_date"=>$stop,"status"=>0,"modified_by"=>$id));
                
                //print_r( $data );
                
                //exit();
                
                $userinfo=$user->find($id);//print_r($userinfo);die();
                
                $userexpireinfo = $userexpire->add($data);
                
                $user->requestLevel($id,1);
                //$userinfo=$user->find($id);//print_r($userinfo);die();
                $_SESSION["user"]->type=1;
                /* Send mail to admin to alert about requesting premium of user */
                //---------------------------------------------------------
                // To send HTML mail, the Content-type header must be set |
                //---------------------------------------------------------
                //---------------------
                // Additional headers |
                //---------------------
                $subject = "Request for Premium Membership";
                $to = "admin@smecaclinic.com";
                $name = $userinfo[0]->first_name . " " . $userinfo[0]->last_name ;
                $ref = $ref = $user->getRef("Request for Premium Membership","RPM",0); // RPM = Request for Premium Membership

                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                $headers .= 
                            "From: ". $userinfo[0]->email. "\r\n" .
                            "Reply-To: ".$userinfo[0]->email . "\r\n" ;
                //die($headers);
                
                /* SENDING MAIL TO CLIENT */
                $message ='
                <html>
                <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                </head>
                <body>';
                $message .= '
                    <div style="width:680px;margin-bottom:15px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:11px;">
                        <div align="center"> <img src="' . BASE_URL . IMG_FOLDER. 'logo.png" /> </div>
                    </div>
                    <p  style="width:680px;margin:0 0 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
                        Date &amp; Time : ' . Date('D, Y-m-d h:i:s A') . '
                    </p>
                    <p  style="width:680px;margin:0 0 5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:12px;font-weight:bold">
                        Reference Number : ' . $ref . '
                    </p>            
                    <table style="FONT-FAMILY:Cambria,Arial;BORDER-COLLAPSE:collapse" cellspacing="0" cellpadding="5" width="680" align="left" border="0">
                        <tbody>
                        <tr>
                        </tr>
                        <tr valign="top">
                            <td style="FONT-SIZE:11px" colspan="2" >There is a request for Premium Membership from [' . $name . '] for you to follow through.<br><br>
                            <div>User Details:</div>
                            <div>
                                &nbsp;&nbsp;&nbsp;ID:'.$userinfo[0]->id.'<br/>
                                &nbsp;&nbsp;&nbsp;Name: ' . $name . '<br/>
                                &nbsp;&nbsp;&nbsp;Email: ' . $userinfo[0]->email . '<br/>
                                &nbsp;&nbsp;&nbsp;Phone: ' . $userinfo[0]->phone . '<br/>
                            </div>      
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <!--                    
                    <div style="width:680px;margin:10px auto 15px;padding-top:5px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:11px;border-top:2px solid #ccc">
                        <strong style="">Tel: </strong>(61) 414 282 552 / 403 699 334<br>
                        <strong style="">Email: </strong>admin@smecaclinic.com<br>              
                        <strong style="">Page: </strong> <a href="http://www.smecaclinic.com">http://www.smecaclinic.com</a>
                    </div>
                                        
                    <div style="width:680px;margin:10px auto 15px;FONT-FAMILY:Cambria,helvetica,sans-serif;font-size:11px;text-align:center">
                        <ul style="display:inline-block;margin:auto;padding:0;list-style:none">
                            <li style="margin-bottom:10px">Follow us:</li>
                            <li style="float:left;"><a href="https://www.facebook.com/pages/Smeca-Clinic/558881040810345" style="background: url(' . BASE_URL . IMG_FOLDER . 'icon_sn.png) no-repeat scroll 0 -25px transparent;display: block;height: 25px;width: 25px;"></a></li>
                            <li style="float:left;"><a href="https://twitter.com/SmecaClinic" style=" background: url(' . BASE_URL . IMG_FOLDER .'icon_sn.png) no-repeat scroll 0 -75px transparent;display: block;height: 25px;width: 25px;"></a></li>
                            <li style="float:left;"><a href="http://www.linkedin.com/profile/view?id=245694897&trk=tab_pro" style="background: url(' . BASE_URL . IMG_FOLDER . 'icon_sn.png) no-repeat scroll 0 -125px transparent;display: block;height: 25px;width: 25px;"></a></li>
                            <li style="float:left;"><a href="https://www.youtube.com/SmecaClinic" style=" background: url(' . BASE_URL . IMG_FOLDER .'icon_sn.png) no-repeat scroll 0 -175px transparent;display: block;height: 25px;width: 25px;"></a></li>
                        </ul>
                    </div>
                    -->
                ';
                
                $message .='</body></html>';
                //die($message);
                if(mail($to, $subject, $message, $headers))
                    //echo "Email sent";
                    echo 1;
                else
                    //echo "Email sending failed";
                    echo 0;
                //echo 1;
            }else{
                echo 0;
            }
		}
		
		
		public function logout(){
			if ( $_SESSION["user"]->type == 0 ){
				SESSION::kill("user");
				$this->redirect(array("com"=>"page","action"=>"index"));
			}else{
				SESSION::kill("user");
				$this->redirect(array("com"=>"page","action"=>"index"));
			}
		}
		
		public function isPremium(){
			if(isset($_SESSION["user"])&&$_SESSION["user"]->type==2)echo 1;
			else{echo 0;}
		}
		public function useractivity(){
			$page = $this->loadController("Page");
			$user = SESSION::get("user") ;
			if ( $user!=null && $user->id != "" && $user->email != "" && $user->password != "" ){
				$start = Basic::getVar("start");
				$perpage = Basic::getVar("perpage");
				$search = Basic::getVar("search");
				$start = is_numeric($start)&&$start<1?1:$start;
				$perpage = is_numeric($perpage)&&$perpage>0?$perpage:20;
				$searchColumns = Basic::getVar("search_column")?Basic::getVar("search_column"):false;
				$sortColumn = Basic::getVar("sort_column")?Basic::getVar("sort_column"):"ua.`created`";
				$sortCriteria = Basic::getVar("sort_criteria")?Basic::getVar("sort_criteria"):false;
				$user = $this->loadModel("User");
				$userRecords = $user->displayActivity($start,$perpage,$search,$searchColumns,$sortColumn,$sortCriteria);
				$this->set("currentPage",$start);
				$this->set("perpage",$perpage);
				$this->set("search",$search);
				$this->set("searchColumns",$searchColumns);
				$this->set("sortColumn",$sortColumn);
				$this->set("sortCriteria",$sortCriteria);
				$this->set("search",$search);
				$this->set("users",$userRecords);
				$this->set( "title" , "SMECA ClINIC - User Activity" );
				$this->setLanguage( "English" );
				$this->set("selectedMenu","UAC");
		
				//print_r( $userRecords );
				//exit();
		
				$this->renderDefault("user_activity","user");
			}else{
				$this->redirect(array("com"=>"page","action"=>"login"));
			}
		}
	}
?>